home *** CD-ROM | disk | FTP | other *** search
- #include <windows.h>
-
- #include "std.h"
- #include "dvtools.h"
- #include "dvstd.h"
- #include "Tfundecl.h"
- #include "dvGR.h"
-
- #include "dv_win.h"
-
- long CALLBACK MyWinProc( HWND, UINT, WPARAM, LPARAM );
-
- LOCAL void UpdateDVwindow();
- LOCAL void init_window( char *, HANDLE, int ), init_dv(), term_dv();
-
- LOCAL VIEW MyView[3], ActiveView;
- LOCAL DRAWPORT Dp[3], ActiveDrawport;
- LOCAL OBJECT screen;
-
- LOCAL HWND dv_window;
-
- LRESULT (CALLBACK * dv_winproc)() = NULL ;
-
- int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
-
- MSG msg;
-
-
- /* Register, Create and Draw a window */
- init_window( "DV_WIN", hInstance, nCmdShow );
-
- /* Initialize the DataViews Stuff */
- init_dv();
-
- /* Go into the Message Loop */
- while( GetMessage(&msg, NULL, 0,0) )
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
- }
-
- return msg.wParam;
- }
-
- LOCAL void init_window( char *class_name, HANDLE hInstance, int nCmdShow )
- {
- WNDCLASS wndclass;
-
- /* Register the Class */
- wndclass.style = CS_OWNDC; /* default style */
- wndclass.hInstance = hInstance;
- wndclass.lpszClassName = class_name;
- wndclass.lpszMenuName = "dvMenu";
- wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
- wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
- wndclass.hbrBackground = GetStockObject( GRAY_BRUSH );
- wndclass.lpfnWndProc = MyWinProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
-
- RegisterClass( &wndclass );
-
- /* Create an Instance of the Class */
- dv_window = CreateWindow( class_name, class_name,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 500, 400,
- NULL,
- NULL,
- hInstance,
- NULL );
-
- /* Display the Window */
- ShowWindow( dv_window, nCmdShow );
- UpdateWindow( dv_window );
-
- /* Create a Timer */
- SetTimer( dv_window, 1, 100, NULL );
- }
-
- LOCAL void init_dv()
- {
- /* Initialize DataViews */
- TInit( NULL, NULL );
-
- /* Pass the window onto DataViews */
- screen = TscOpenSet( "W", NULL,
- V_WIN32_WINDOW_HANDLE, dv_window,
- V_ACTIVE_CURSOR,
- V_END_OF_LIST );
-
- /* get a pointer to the function that would */
- /* be the window proc for a window created */
- /* with TscOpenSet */
- GRget(V_WIN32_WINDOWPROC,&dv_winproc,V_END_OF_LIST);
- GRset(V_WIN32_DOUBLE_BUFFER,TRUE,V_END_OF_LIST);
-
- /* Load the two Views, Create Drawports and Draw */
- MyView[1] = TviLoad( "view1.v" );
- TviOpenData( MyView[1] );
- MyView[2] = TviLoad( "view2.v" );
- TviOpenData( MyView[2] );
- MyView[0] = TviLoad( "view3.v" );
- TviOpenData( MyView[0] );
- ActiveView = MyView[0];
-
- Dp[0] = TdpCreate( screen, MyView[0], (RECTANGLE*)NULL, (RECTANGLE*)NULL );
- Dp[1] = TdpCreate( screen, MyView[1], (RECTANGLE*)NULL, (RECTANGLE*)NULL );
- Dp[2] = TdpCreate( screen, MyView[2], (RECTANGLE*)NULL, (RECTANGLE*)NULL );
- ActiveDrawport = Dp[0];
-
- TviReadData( ActiveView );
- TdpDraw( ActiveDrawport );
- }
-
- LOCAL void term_dv()
- {
- return;
-
- TdpDestroy( Dp[0] );
- TdpDestroy( Dp[1] );
- TdpDestroy( Dp[2] );
-
- TviDestroy( MyView[0] );
- TviDestroy( MyView[1] );
- TviDestroy( MyView[2] );
-
- TscCloseCurrentScreen();
-
- TTerminate();
- }
-
- /* this window proc calls the dataviews window proc to */
- /* handle any messages that need not be handled directly */
- /* by this app. some of the things this proc lets the */
- /* dataviews window proc handle are: */
- /* mapping of windows messages to expose events */
- /* mapping of windows messages to resize events */
- /* color table handling */
- /* Handle any messages you wish. If you handle the */
- /* message there is no need to call the dataviews window */
- /* proc and you should not do so. */
- long CALLBACK MyWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
- {
- PAINTSTRUCT ps;
- int id;
- MSG a_msg; /* used to call GRwe_convert() */
- WINEVENT win_event; /* used to call GRwe_convert() */
- static int times = 0; /* used as a counter to toggle */
- /* double buffering on and off */
- static int a_bool = TRUE; /* true for turning on double */
- /* buffering */
- static int ok_to_draw=TRUE;
-
- switch( msg )
- {
- case WM_CANCELMODE:
- /* this message will be sent when the graph view is */
- /* is sized too small and a message box displays */
- /* the viewport too small message. redrawing the */
- /* view while the message box is up will result in */
- /* an endless stream of errors. */
- ok_to_draw = FALSE;
- return(0);
- break;
- case WM_ACTIVATE:
- /* this message is sent when the message box is */
- /* dismissed */
- if ( ( LOWORD(wParam) == WA_ACTIVE ) ||
- ( LOWORD(wParam) == WA_CLICKACTIVE ) )
- ok_to_draw = TRUE;
- return(0);
- break;
- case WM_DESTROY:
- term_dv();
- PostQuitMessage( 0 );
- return( 0 );
- break;
-
- case WM_TIMER:
- if ( ok_to_draw == TRUE )
- UpdateDVwindow();
- times++;
- if ( times % 30 == 0 )
- {
- /* every 30 times the timer sends a message */
- /* toggle the state of double buffering */
- a_bool = ( a_bool == TRUE ) ? FALSE : TRUE;
- GRset(V_WIN32_DOUBLE_BUFFER,a_bool,0);
- }
- break;
-
- case WM_SYSCOMMAND:
- switch (LOWORD (wParam))
- {
- case SC_CLOSE:
- PostQuitMessage( 0 );
- return( 0 );
- break;
-
- default:
- return DefWindowProc( hwnd, msg, wParam, lParam );
- }
- break;
-
- case WM_COMMAND:
- switch( LOWORD( wParam) )
- {
- case IDM_QUIT:
- term_dv();
- PostQuitMessage( 0 );
- return( 0 );
- break;
- case IDM_GRAPH:
- ActiveView = MyView[0];
- ActiveDrawport = Dp[0];
- TdpDraw( ActiveDrawport );
- break;
- case IDM_ANIM:
- ActiveView = MyView[1];
- ActiveDrawport = Dp[1];
- TdpDraw( ActiveDrawport );
- break;
- case IDM_LOGO:
- ActiveView = MyView[2];
- ActiveDrawport = Dp[2];
- TdpDraw( ActiveDrawport );
- break;
- }
- break;
- case WM_LBUTTONDOWN:
- if( ActiveDrawport == Dp[0] )
- id = 1;
- else
- if ( ActiveDrawport == Dp[1] )
- id = 2;
- else
- id = 0;
- ActiveView = MyView[id];
- ActiveDrawport = Dp[id];
- TdpDraw( ActiveDrawport );
- break;
-
- case WM_CHAR:
- if ( (wParam == 'c') || ( wParam == 'C' ) )
- GRerase();
- break;
-
- /* VI_RESIZE and VI_EXPOSE are defined in dvGR.h */
-
- case VI_EXPOSE:
- a_msg.hwnd = hwnd;
- a_msg.message = msg;
- a_msg.wParam = wParam;
- a_msg.lParam = lParam;
- /* here, GRwe_convert() will fill in the region that */
- /* should be sent with TscRedraw */
- GRwe_convert(&a_msg,&win_event);
- if ( ok_to_draw == TRUE )
- TscRedraw(screen,&(win_event.region));
- break;
-
- case VI_RESIZE:
- TscReset(screen);
- break;
-
- case WM_PAINT:
- if ( dv_winproc == NULL )
- {
- BeginPaint(hwnd, &ps);
- EndPaint(hwnd,&ps);
- }
- else
- {
- /* this is how you should handle a WM_PAINT message for */
- /* a DVtools window */
- a_msg.hwnd = hwnd;
- a_msg.message = msg;
- a_msg.wParam = wParam;
- a_msg.lParam = lParam;
- /* GRwe_convert will call BeginPaint() and EndPaint() */
- /* and fill in the win_event structure with the rectangle */
- /* that needs to be redrawn */
- GRwe_convert(&a_msg,&win_event);
- if ( win_event.type == V_EXPOSE )
- TscRedraw(screen,&(win_event.region));
- }
- return(0);
- break;
-
- default:
- /* using this method will also take care of */
- /* handling the color table. */
- if ( dv_winproc != NULL )
- {
- return( CallWindowProc(dv_winproc,hwnd, msg, wParam, lParam ));
- }
- return DefWindowProc( hwnd, msg, wParam, lParam );
- break;
- }
- return(0);
- }
-
- LOCAL void UpdateDVwindow()
- {
-
- TviReadData( ActiveView );
- TdpDrawNext( ActiveDrawport );
- }
-
- LOCAL void HandleDVwindowEvents()
- {
-
- }
-